package flc.ast.widget.time;

import android.annotation.SuppressLint;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.graphics.Color;
import android.widget.RemoteViews;

import com.blankj.utilcode.util.TimeUtils;

import java.text.SimpleDateFormat;

import flc.ast.R;
import flc.ast.utils.AppSpUtils;
import flc.ast.utils.BatteryUtil;
import stark.common.basic.utils.BitmapUtil;

public class Time3Widget extends BaseTimeWidget {

    public Time3Widget(int appWidgetId) {
        super(appWidgetId);
    }

    @Override
    protected void onUpdate(Context context) {
        @SuppressLint("RemoteViewLayout") RemoteViews remoteViews =
                new RemoteViews(context.getPackageName(), R.layout.widget_time3);
        //准备数据
        BatteryUtil.ReceiverBatteryOtherInfo(context);
        String date = TimeUtils.getNowString(new SimpleDateFormat("MM月dd日 EEEE"));
        String time = TimeUtils.getNowString(new SimpleDateFormat("HH:mm"));
        //更新显示数据
        String time3Color = AppSpUtils.getTime3Color();
        remoteViews.setTextViewText(R.id.tvTime3Date, date);
        remoteViews.setImageViewBitmap(R.id.tvTime3Time, BitmapUtil.text2BmpWithAssetFont(context, time,
                Color.parseColor(time3Color), 40, "font/ziti5.ttf"));
        remoteViews.setTextViewText(R.id.tvTime3Level, context.getString(R.string.level_text)
                + BatteryUtil.level + "%");
        remoteViews.setTextColor(R.id.tvTime3Date, Color.parseColor(time3Color));

        remoteViews.setInt(R.id.llTime3Bg, "setBackgroundColor", AppSpUtils.getTime3Bg());

        AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews);
    }
}